package cn.edu.neusoft.maxingxin231.yuejian06.Activity;

import android.graphics.Color;
import android.net.Uri;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.w3c.dom.Text;

import cn.edu.neusoft.maxingxin231.yuejian06.Fragment.AllOrderFragment;
import cn.edu.neusoft.maxingxin231.yuejian06.Fragment.FinishOrderFragment;
import cn.edu.neusoft.maxingxin231.yuejian06.Fragment.UnFinishFragment;
import cn.edu.neusoft.maxingxin231.yuejian06.R;

public class OrderListActivity extends BaseActivity implements View.OnClickListener,
        AllOrderFragment.OnFragmentInteractionListener,
        FinishOrderFragment.OnFragmentInteractionListener ,
        UnFinishFragment.OnFragmentInteractionListener {
    ImageButton btn_back;
    LinearLayout tab_all,tab_wc,tab_dcj;
    TextView tv_all,tv_wc,tv_dcj;
    Fragment fragment_all_order;
    Fragment fragment_finish_order;
    Fragment fragment_unfinish;
    FragmentManager fragmentManager;
    FragmentTransaction fragmentTransaction;


    @Override
    void initView() {
        setLayout_file(R.layout.activity_order_list);
        btn_back = (ImageButton)findViewById(R.id.btn_back);
        tv_wc = (TextView)findViewById(R.id.tv_wc);
        tv_dcj = (TextView) findViewById(R.id.tv_dcj);
        tv_all = (TextView)findViewById(R.id.tv_all);
        tab_wc = (LinearLayout) findViewById(R.id.tab_wc);
        tab_dcj = (LinearLayout) findViewById(R.id.tab_dcj);
        tab_all = (LinearLayout) findViewById(R.id.tab_all);
        setSelect(0);

    }

    @Override
    void initEvent() {
        tab_wc.setOnClickListener(this);
        tab_dcj.setOnClickListener(this);
        tab_all.setOnClickListener(this);

        //返回
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tab_wc:
                setSelect(0);
                break;
            case  R.id.tab_dcj:
                setSelect(1);
                break;
            case  R.id.tab_all:
                setSelect(2);
                break;
        }
    }

    private void setSelect(int i){
        fragmentManager = getSupportFragmentManager();
        fragmentTransaction = fragmentManager.beginTransaction();
        hideFragment(fragmentTransaction);
        switch (i){
            case 0:
                if (fragment_finish_order == null){
                    fragment_finish_order = new FinishOrderFragment();
                    fragmentTransaction.add(R.id.content,fragment_finish_order);
                }else{
                    fragmentTransaction.show(fragment_finish_order);
                }
                tv_wc.setBackgroundColor(Color.parseColor("#AEEEEE"));
                tv_dcj.setBackgroundColor(Color.parseColor("white"));
                tv_all.setBackgroundColor(Color.parseColor("white"));
                break;
            case 1:
                if (fragment_unfinish == null){
                    fragment_unfinish = new UnFinishFragment();
                    fragmentTransaction.add(R.id.content,fragment_unfinish);
                }else{
                    fragmentTransaction.show(fragment_unfinish);
                }
                tv_wc.setBackgroundColor(Color.parseColor("white"));
                tv_dcj.setBackgroundColor(Color.parseColor("#AEEEEE"));
                tv_all.setBackgroundColor(Color.parseColor("white"));
                break;
            case 2:
                if (fragment_all_order == null){
                    fragment_all_order = new AllOrderFragment();
                    fragmentTransaction.add(R.id.content,fragment_all_order);
                }else{
                    fragmentTransaction.show(fragment_all_order);
                }
                tv_wc.setBackgroundColor(Color.parseColor("white"));
                tv_dcj.setBackgroundColor(Color.parseColor("white"));
                tv_all.setBackgroundColor(Color.parseColor("#AEEEEE"));
                break;
             default:
                 break;
        }
        fragmentTransaction.commit();
    }

    private void hideFragment(FragmentTransaction fragmentTransaction){
        if (fragment_finish_order!=null){
            fragmentTransaction.hide(fragment_finish_order);
        }
        if (fragment_unfinish!=null){
            fragmentTransaction.hide(fragment_unfinish);
        }
        if(fragment_all_order!=null){
            fragmentTransaction.hide(fragment_all_order);
        }
    }

    @Override
    void initData() {

    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}
